home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-15 | 3.4 KB | 132 lines | [TEXT/PJMM] |
- unit shots;
-
- interface
-
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Events, Menus, Dialogs, Fonts, Resources, Devices,
- {$ENDC}
- Globals, Util, Ships;
-
- procedure InitShots;
- procedure CreateShot (c: RGBColor; h, v, hv, vv: Integer);
- procedure MoveShots;
- procedure DrawShots;
-
-
- implementation
-
- procedure InitShots;
- var
- { myWhite, myBlack, myRed, myBlue, myYellow, myGreen, myOrange, myGray, myDkBlue: }
- { RGBColor extern;}
- { gShotRecs[MAX_SHOTS]}
- { , gOldShotRecs [ MAX_SHOTS ] : SHOTREC extern; }
- i, nc: Integer;
- begin
- for i := 0 to MAX_SHOTS - 1 do
- begin
- gShotRecs[i].where.v := -1;
- gShotRecs[i].where.h := -1;
- gShotRecs[i].vel.v := -1;
- gShotRecs[i].vel.h := -1;
- gShotRecs[i].lifeSpan := 0;
- gShotRecs[i].isAlive := FALSE;
- end; (* for *)
-
- end; (* InitShots() *)
-
- procedure CreateShot (c: RGBColor; h, v, hv, vv: Integer);
- var
- i: Integer;
- begin
- for i := 0 to MAX_SHOTS - 1 do
- if (not gShotRecs[i].isAlive) then
- begin
- gShotRecs[i].where.v := v;
- gShotRecs[i].where.h := h;
- gShotRecs[i].vel.v := vv;
- gShotRecs[i].vel.h := hv;
- gShotRecs[i].isAlive := TRUE;
- gShotRecs[i].lifeSpan := 20;
- gShotRecs[i].color := c;
- exit(CreateShot);
- end; (* if *)
- end; (* CreateShot() *)
-
- procedure MoveShots;
- var
- i: Integer;
- { gShotRecs[MAX_SHOTS]}
- { : }
- { SHOTREC extern; }
- begin
- for i := 0 to MAX_SHOTS - 1 do
- if (gShotRecs[i].isAlive) then
- begin
- if (gShotRecs[i].lifeSpan <> 0) then
- begin
- gShotRecs[i].lifeSpan := gShotRecs[i].lifeSpan - 1;
- gShotRecs[i].where.h := gShotRecs[i].where.h + gShotRecs[i].vel.h;
- gShotRecs[i].where.v := gShotRecs[i].where.v + gShotRecs[i].vel.v;
- if (gShotRecs[i].where.h > 637) then
- begin
- gShotRecs[i].vel.h := -gShotRecs[i].vel.h;
- gShotRecs[i].where.h := 637;
- end; (* if *)
- if (gShotRecs[i].where.h < 1) then
- begin
- gShotRecs[i].vel.h := -gShotRecs[i].vel.h;
- gShotRecs[i].where.h := 1;
- end; (* if *)
- if (gShotRecs[i].where.v > 477) then
- begin
- gShotRecs[i].vel.v := -gShotRecs[i].vel.v;
- gShotRecs[i].where.v := 477;
- end; (* if *)
- if (gShotRecs[i].where.v < 21) then
- begin
- gShotRecs[i].vel.v := -gShotRecs[i].vel.v;
- gShotRecs[i].where.v := 21;
- end; (* if *)
- end (* if *)
- else
- gShotRecs[i].isAlive := FALSE;
- end; (* if *)
-
- end; (* MoveShots() *)
-
- procedure DrawShots;
- var
- savePort: GrafPtr;
- i, j: Integer;
- dstRect: Rect;
- begin
- GetPort(savePort);
- SetPort(GrafPtr(gOSPtr));
- for i := 0 to MAX_SHOTS - 1 do
- begin
- if gOldShotRecs[i].isAlive then
- SetCPixel(gOldShotRecs[i].where.h, gOldShotRecs[i].where.v, myBlack);
- if gShotRecs[i].isAlive then
- begin
- SetCPixel(gShotRecs[i].where.h, gShotRecs[i].where.v, gShotRecs[i].color);
- gOldShotRecs[i] := gShotRecs[i];
- dstRect.top := gShotRecs[i].where.v;
- dstRect.left := gShotRecs[i].where.h;
- dstRect.bottom := dstRect.top + 1;
- dstRect.right := dstRect.left + 1;
- for j := 0 to MAX_PLAYERS - 1 do
- if not ColorsEqual(gShotRecs[i].color, gShipRecs[j].color) then
- if CheckForShipCollision(j, dstRect) then
- begin
- gShotRecs[i].isAlive := FALSE;
- KillPlayer(j);
- end; (* if *)
- end; (* if *)
- end; (* for *)
- SetPort(GrafPtr(savePort));
-
- end; (* DrawShots() *)
-
- end.